﻿using MiniErp.Model.Entities;
using MiniErp.Model.Entities.AssetManagement;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MiniErp.Mysql.Data
{
    public static class DbInitializer
    {
        public static void Initialize(MysqlContext _context)
        {
            _context.Database.EnsureCreated();
            if (!_context.UserInfos.Any())
            {
                var userInfos = new List<UserInfoEntity>
            {
            new UserInfoEntity{UId=210001,PassWord="123456",UserName="张三",State=true,PhoneNumber=12345678901,MailBox="",Rights=1},
            new UserInfoEntity{UId=210002,PassWord="123456",UserName="李四",State=true,PhoneNumber=12345678901,MailBox="",Rights=1},
            new UserInfoEntity{UId=210003,PassWord="123456",UserName="王五",State=true,PhoneNumber=12345678901,MailBox="",Rights=1},
            new UserInfoEntity{UId=210004,PassWord="123456",UserName="赵六",State=true,PhoneNumber=12345678901,MailBox="",Rights=1},
            };
                userInfos.ForEach(item =>
                {
                    _context.UserInfos.Add(item);
                });
                _context.SaveChanges();
            }

            if (!_context.AssetStates.Any())
            {
                var assetStates = new List<AssetStateEntity>
            {
            new AssetStateEntity{AssetStateId=1,AssetStateName="空闲"},
            new AssetStateEntity{AssetStateId=2,AssetStateName="外借"},
            new AssetStateEntity{AssetStateId=3,AssetStateName="维修"}
            };
                assetStates.ForEach(item =>
                {
                    _context.AssetStates.Add(item);
                });
                _context.SaveChanges();
            }

            if (!_context.GeneralTypes.Any())
            {
                var generalType = new List<GeneralTypeEntity>
            {
            new GeneralTypeEntity{GeneralTypeId=1001,GeneralTypeName="生产用品"},
            new GeneralTypeEntity{GeneralTypeId=1002,GeneralTypeName="办公用品"},
            new GeneralTypeEntity{GeneralTypeId=1003,GeneralTypeName="基建用品"},
            };
                generalType.ForEach(item =>
                {
                    _context.GeneralTypes.Add(item);
                });
                _context.SaveChanges();
            }

            if (!_context.SecondaryTypes.Any())
            {
                var secondaryType = new List<SecondaryTypeEntity>
            {
            new SecondaryTypeEntity{SecondaryTypeId=1001,SecondaryTypeName="产测电脑"},
            new SecondaryTypeEntity{SecondaryTypeId=1002,SecondaryTypeName="办公电脑"}
            };
                secondaryType.ForEach(item =>
                {
                    _context.SecondaryTypes.Add(item);
                });
                _context.SaveChanges();
            }

            if (!_context.Departments.Any())
            {
                var departments = new List<DepartmentEntity>
            {
            new DepartmentEntity{DepartmentId=100001,DepartmentName="工程部"},
            new DepartmentEntity{DepartmentId=100002,DepartmentName="咨询部"}
            };
                departments.ForEach(item =>
                {
                    _context.Departments.Add(item);
                });
                _context.SaveChanges();
            }

            if (!_context.Positions.Any())
            {
                var positions = new List<PositionEntity>
            {
            new PositionEntity{PositionId=100001,PositionName="工程部办公室",PositionAddress="A栋一楼右侧"},
            new PositionEntity{PositionId=100002,PositionName="TE办公室",PositionAddress="工程部大办公室旁，A栋一楼右侧"},
            new PositionEntity{PositionId=100003,PositionName="TE仓库",PositionAddress="B栋一楼右侧"},
            new PositionEntity{PositionId=100004,PositionName="咨询部",PositionAddress="A栋一楼左侧"},
            };
                positions.ForEach(item =>
                {
                    _context.Positions.Add(item);
                });
                _context.SaveChanges();
            }


            if (!_context.AssetInfos.Any())
            {
                var assetInfos = new List<AssetInfoEntity>
            {
            new AssetInfoEntity{AId=100001,GeneralTypeId=1001,SecondaryTypeId=1001,DepartmentId=100001,UserInfoId=210001,AssetStateId=1,AssetName="Win10测试电脑",PositionId=100003},
            new AssetInfoEntity{AId=100002,GeneralTypeId=1002,SecondaryTypeId=1002,DepartmentId=100001,UserInfoId=210001,AssetStateId=1,AssetName="Win10测试电脑",PositionId=100003},
            new AssetInfoEntity{AId=100003,GeneralTypeId=1001,SecondaryTypeId=1001,DepartmentId=100001,UserInfoId=210003,AssetStateId=2,AssetName="Win10测试电脑",PositionId=100002},
            new AssetInfoEntity{AId=100004,GeneralTypeId=1001,SecondaryTypeId=1002,DepartmentId=100001,UserInfoId=210001,AssetStateId=1,AssetName="Win10测试电脑",PositionId=100004},
            new AssetInfoEntity{AId=100005,GeneralTypeId=1002,SecondaryTypeId=1001,DepartmentId=100002,UserInfoId=210002,AssetStateId=3,AssetName="Win10测试电脑",PositionId=100003},
            new AssetInfoEntity{AId=100006,GeneralTypeId=1001,SecondaryTypeId=1001,DepartmentId=100001,UserInfoId=210001,AssetStateId=1,AssetName="Win10测试电脑",PositionId=100003}
            };
                assetInfos.ForEach(item =>
                {
                    _context.AssetInfos.Add(item);
                });
                _context.SaveChanges();
            }
        }
    }
}
